package com.aier.admin.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.admin.common.AdminFinalPageSize;
import com.aier.admin.common.AdminIcardData;
import com.aier.admin.entity.IcCard;
import com.aier.admin.service.IAdminAssignCardService;
import com.aier.common.dao.ICommonDAO;

@Scope("prototype")
@Component("adminAssignCardAction")
public class AdminAssignCardAction extends AdminBaseAction {
    private static final long serialVersionUID = 1L;

    private int a;
    private int b;
    private List<IcCard> icCards;
    private String ichead;
    private String icbody1;
    private String icbody2;
    private int s;
    private Integer pid;
    private List<Long> cids;
    private List<IcCard> icCards2;
    private List<IcCard> icCards3;

    // 当前页
    private int page;
    // 每页显示记录数
    private int page_size;
    // 总页数
    private int page_count;
    // 总数
    private int count;
    
    private String account;

    /**
     * 分派卡
     */
    @Override
    public String execute() {
        return SUCCESS;
    }

    @Resource(name = "adminAssignCardService")
    private IAdminAssignCardService adminAssignCardService;

    /**
     * 查询未分派的卡
     * 
     * @return
     */
    @SuppressWarnings("unchecked")
    public String searchAssignCard() {

        if (page <= 0) {
            page = 1;
        }
        Map<String, Object> map = null;
        map = adminAssignCardService.searchAssignCard(
                AdminIcardData.ICARD_STATE_NOTACTIVATED,
                AdminIcardData.ICARD_STATE_UNALLOCATED, page,
                AdminFinalPageSize.UNALLOCATED_ICARD_PAGESIZE);
        icCards = (List<IcCard>) map.get(ICommonDAO.OBJ_LIST);
        if (null == icCards) {
            s = 0;
            return SUCCESS;
        }
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        s = 1;
        return SUCCESS;
    }

    /**
     * 为未分派的卡添加代理
     * 
     * @return
     */
    public String insertCardProxy() {
        s = adminAssignCardService.updateCardProxy(ichead, icbody1, icbody2, pid);
        try {
            icCards3 = adminAssignCardService.searchProxyCard();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return SUCCESS;
    }

    /**
     * 显示已经分配的卡
     * 
     * @return
     */

    public int getA() {
        return a;
    }

    public void setA(int a) {
        this.a = a;
    }

    public int getB() {
        return b;
    }

    public void setB(int b) {
        this.b = b;
    }

    public List<IcCard> getIcCards() {
        return icCards;
    }

    public int getS() {
        return s;
    }

    public void setS(int s) {
        this.s = s;
    }

    public Integer getPid() {
        return pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

    public List<Long> getCids() {
        return cids;
    }

    public void setCids(List<Long> cids) {
        this.cids = cids;
    }

    public String getIchead() {
        return ichead;
    }

    public void setIchead(String ichead) {
        this.ichead = ichead;
    }

    public String getIcbody1() {
        return icbody1;
    }

    public void setIcbody1(String icbody1) {
        this.icbody1 = icbody1;
    }

    public String getIcbody2() {
        return icbody2;
    }

    public void setIcbody2(String icbody2) {
        this.icbody2 = icbody2;
    }

    public List<IcCard> getIcCards2() {
        return icCards2;
    }

    public void setIcCards2(List<IcCard> icCards2) {
        this.icCards2 = icCards2;
    }

    public List<IcCard> getIcCards3() {
        return icCards3;
    }

    public void setIcCards3(List<IcCard> icCards3) {
        this.icCards3 = icCards3;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPage_size() {
        return page_size;
    }

    public int getPage_count() {
        return page_count;
    }

    public int getCount() {
        return count;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

}
